package com.zsk.blog.controller;

import com.zsk.blog.entity.Project;
import com.zsk.blog.repository.ProjectRepository;
import com.zsk.blog.service.ProjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/user")
public class ProjectHandler {

    @Autowired
    ProjectRepository projectRepository;

    @PostMapping("/project")
    public List<Project> findAllById(@RequestBody Map<String,String > data){
        System.out.println(data);
        String companyid =  data.get("companyid");
        Integer companyId = Integer.parseInt(companyid);
        System.out.println(companyId);
        return projectRepository.findAllByCompanyid(companyId);
    }

    @GetMapping("/getstr")
    public  Map<String ,String > getStr(){
        Map data = new HashMap();
        data.put("hehe","heihei");
        return data;
    }

    @PostMapping("/addProject")
    public Map<String, Object> addProject(@RequestBody Project project){
        System.out.println(project);
        Project project1 = projectRepository.save(project);
        Map response = new HashMap();
        if (project1 == null) {
            response.put("code","400");
            response.put("message","添加失败，原因不知道。");
        }else  {
            response.put("code","200");
            response.put("message","添加成功");
            response.put("data",project1);
        }
        return response;
    }
}
